﻿<?php

/**
 * @file
 * Customize the e-mails sent by Webform after successful submission.
 *
 * This file may be renamed "webform-mail-[nid].tpl.php" to target a
 * specific webform e-mail on your site. Or you can leave it
 * "webform-mail.tpl.php" to affect all webform e-mails on your site.
 *
 * Available variables:
 * - $node: The node object for this webform.
 * - $submission: The webform submission.
 * - $email: The entire e-mail configuration settings.
 * - $user: The current user submitting the form.
 * - $ip_address: The IP address of the user submitting the form.
 *
 * The $email['email'] variable can be used to send different e-mails to different users
 * when using the "default" e-mail template.
 */
?>
<?php if (stripos($email['email'], 'petr.felzmann@centrum.cz') !== false || stripos($email['email'], 'pavlina.stachovska@centrum.cz') !== false || stripos($email['email'], 'jiri.stachovsky@centrum.cz') !== false): ?>
Odeslano z IP adresy %ip_address
Rezervace c. %sid.
%email_values
%email[accomodation_price]
%email[municipal_tax]
%email[full_price]
<?php else: ?>
<?php
function _get_accomodation_for_mail($accomodation) {
	$result = "";
	$separator = "";
	foreach ($accomodation as $acc) {
		$result .= $separator;
		$separator = ", ";
		switch ($acc) {
			case 'pr': $result .= t("Apartmen Priessnitz"); break;
			case 'kn': $result .= t("Apartmen Kneipp"); break;
			case 'ch': $result .= t("Cottage"); break;
		}
	}
	return $result;
}

print "<p>" . t("Hello,") . "</p>" . "\n\n";
print "<p>" . t("Thank you for your accommodation booking of Montanus apartments.") . "</p>" . "\n\n";
print "<p>" . t("You booked:") . "\n";
print "<ul>";
print "<li>" . t("Date:") . " %value[arrival] &ndash; %value[departure]" . "</li>" . "\n";
print "<li>" . t("Accommodation:") . " " . _get_accomodation_for_mail($submission->data[3]['value']) . "</li>" . "\n";
print "<li>" . t("Number of adults:") . " %value[adult_count]" . "</li>" . "\n";
print "<li>" . t("Accommodation price:") . " %value[accomodation_price]" . "</li>" . "\n";
print "<li>" . t("Municipal tax:") . " %value[municipal_tax]" . "</li>" . "\n";
print "<li>" . t("Full price:") . " %value[full_price]" . "</li>" . "\n\n";
print "</ul></p>";

$arrival = strtotime($submission->data[1]['value'][0]);

if (strtotime("+5 days") >= $arrival) {
	print "<p>" . t("Call @contactphone, please, to agree on payment and apartment’s keys delivery.", array('@contactphone' => variable_get('mt_booking_contactphone'))) . "</p>" . "\n\n";
	print "<p><em>" . t("Your Montanus team") . "</em></p><img src='http://montanus.cz/sites/all/themes/mybartik/images/montanus-mail-logo.png' alt='Montanus logo' />";
}
else {
	print "<p>";
	if (strtotime("+17 days") >= $arrival) {
		print t("Make payment of the full price, i.e. @fullprice Kč, at the least by tomorrow @tomorrow, please.", array(
			'@fullprice' => $submission->data[20]['value'][0],
			'@tomorrow' => date('Y-m-d', strtotime(date('Y-m-d')."+ 1 day"))));
	}
	else if (strtotime("+1 month") >= $arrival) {
		print t("Make payment of the half price, i.e. @halfprice Kč, at the least by tomorrow @tomorrow, please.", array(
			'@halfprice' => intval(intval($submission->data[10]['value'][0]) / 2),
			'@tomorrow' => date('Y-m-d', strtotime(date('Y-m-d')."+ 1 day"))));
	}
	else {
		print t("Make payment of the half price, i.e. @halfprice Kč, at the least by @date, please.", array(
			'@halfprice' => intval(intval($submission->data[10]['value'][0]) / 2),
			'@date' => date('Y-m-d', strtotime(date('Y-m-d')."+ 7 days"))));
	}

	print t(" The account number is @accountnumber, variable symbol: @variablesymbol.", array(
		'@accountnumber' => variable_get('mt_booking_accountnumber'),
		'@variablesymbol' => '%sid')) . "\n";
	
	print "</p>";

	if (strtotime("+17 days") < $arrival) {
		print "<p>" . t("The reservation is considered expired in case of unexecuted advanced payment.") . "</p>" . "\n";
	}

	print "<p>" . t("Introduce always the variable symbol, please; otherwise your payment cannot be assigned.") . "</p>" . "\n";

	if (strtotime("+17 days") >= $arrival) {
		print "<p>" . t("You will receive an email after the payment reception, containing the information regarding the keys delivery.") . "</p>" . "\n";
	}

	print "<p>" . t("You can reply to this email directly in case of any question.") . "</p>" . "\n\n";
	print "<p><em>" . t("Your Montanus team") . "</em></p><img src='http://montanus.cz/sites/all/themes/mybartik/images/montanus-mail-logo.png' alt='Montanus logo' />";
}
?>
<?php endif; ?>
